package com.config;


import org.apache.commons.configuration.CompositeConfiguration;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;


public class GenericConfig {
	private static GenericConfig instance = new GenericConfig();
	private static final String CONF_FILE = "config.properties";
	private Configuration config = null;

	
	private GenericConfig() {
		try {
//			System.out.println("loading config files ...");
			Configuration conf = new PropertiesConfiguration(CONF_FILE);

			CompositeConfiguration cc = new CompositeConfiguration();
			cc.addConfiguration(conf);
			config = cc;
		} catch (ConfigurationException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 方法：getInstance<br/>. 获得Singlton的一个类实例
	 * 
	 * @return static的类实例
	 */
	public static final GenericConfig getInstance() {
		return instance;
	}


	public String getFileBase()
	{
		String filebase = config.getString("filebase");
		if (!filebase.endsWith("/"))
        {
			filebase = filebase + "/";
        }
		
		return filebase;
	}
	
	public String getMaterial()
	{
		String material =  config.getString("material");
		if(!material.endsWith("/"))
		{
			material = material + "/";
		}
		return material;
	}
	
}
